package com.example.lenovo.demo.presenter;

import android.app.ProgressDialog;
import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.example.lenovo.demo.model.Model;
import com.example.lenovo.demo.model.databean.CityFirstHotBean;
import com.example.lenovo.demo.model.idatabean.IModel;
import com.example.lenovo.demo.model.idatabean.OnCityFirstHotSuccess;
import com.example.lenovo.demo.presenter.adapter.CityFirstHot_RvAdapter;
import com.example.lenovo.demo.view.ifgview.ICityFirstHotFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Lenovo on 2017/1/15.
 */

public class CityFirstHotFgPresenter implements ICityFirstHotFragment {
    private RecyclerView recyclerView;
    private Context context;
    private ProgressDialog progressDialog;
    private String id;
    private  CityFirstHot_RvAdapter adapter;
    private IModel iModel;
    private List<CityFirstHotBean.DataBean> data;

    public void initData(){
     //   progressDialog.show();
        data=new ArrayList<>();
        iModel=new Model();
        iModel.sendCityFirstHotBean(id, new OnCityFirstHotSuccess() {
            @Override
            public void CityFirstHotsuccess(CityFirstHotBean cityFirstHotBean) {
                data.addAll(cityFirstHotBean.getData());
                LinearLayoutManager manager=new LinearLayoutManager(context,LinearLayoutManager.VERTICAL,false);
                manager.setAutoMeasureEnabled(true);
                recyclerView.setLayoutManager(manager);
                adapter=new CityFirstHot_RvAdapter(data,context);
                recyclerView.setAdapter(adapter);
                CityFirstHotAcPresenter.progressDialog.dismiss();
             //   progressDialog.dismiss();
            }

            @Override
            public void CityFirstHotFaild(CityFirstHotBean cityFirstHotBean) {

            }
        });

    }
    @Override
    public void sendView(RecyclerView recyclerView, Context context, String id, ProgressDialog progressDialog) {
        this.context=context;
        this.id=id;
        this.progressDialog=progressDialog;
        this.recyclerView=recyclerView;
    }
}
